<%-- 
    Document   : Flights
    Created on : Nov 1, 2011, 11:47:14 PM
    Author     : Mr-aUgust
--%>

<%@page pageEncoding="UTF-8"%>
<%@ page session="true" import="java.util.Collection,DAL.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>East2West Tours and Travels</title>
        <script src="../js/jqueryvalidate.js" type="text/javascript"></script>
        <script src="../js/jquery.validate.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function() {
            $("#formflight").validate
                ({
                    rules:{
                        flightname:{ required: true},
                        price:{ required: true},
                        departurTime:{required: true},
                        arrivalTime:{required: true}
                    },
                    messages: {
                        flightname:{required:"*"},
                        price:{ required:"*"},
                        departurTime:{required: "*"},
                        arrivalTime:{required: "*"}
                        }            
                });   
                
            });
            $(document).ready(function() {
            $("#formflightupdate").validate
                ({
                    rules:{
                        flightname:{ required: true},
                        price:{ required: true},
                        departurTime:{required: true},
                        arrivalTime:{required: true}
                    },
                    messages: {
                        flightname:{required:"*"},
                        price:{ required:"*"},
                        departurTime:{required: "*"},
                        arrivalTime:{required: "*"}
                    }            
                });   
                
            });
         </script>
        <style type="text/css">
            .khunvien
           {
                width:630px;
                height:450px;
                background-color:#f0f3ec;
                margin-top:0px;
           }
            #Table
            {
            border:1px solid green;
            }
            th
            {
            border:1px solid green;
            background-color:green;
            color:white;
            }
            .td
            {
            border:1px solid green;
            }
            .font
            {
            font-family:"Times New Roman", Times, serif;
            font-size:x-large;
            font-weight:bold;
            width:200px;
            margin-left:auto;
            margin-right:auto;
            color:#0707e7;
            }
            #reset
            {
            width:120px;
            }
            #list
            {
             width:140px;
            }
            .sizeedit
            {
                width:50px;
            }
        </style>
    </head>
    <body>
        <div class="khunvien">
        <%
                 session.removeAttribute("statusH");
                 String flightID="",flightName="",departureTime="",arrivalTime="",nameCity="",departurecity="",arrivalcity="",price="",timedeparture="",timearra="";
                 if(session.getAttribute("status")==null)
                     {
                        LocationBean lcbean=new LocationBean();
                        Collection lction=lcbean.ListLocation();
                        request.setAttribute("lc1",lction);
        %>
        <form action="../ControllerFlight" method="get" name="formflight" id="formflight">
            <table width="650px" border="0" cellpadding="5" cellspacing="5">
                <tr>
                    <td colspan="2" class="font" align="center">Create Flight</td>
                </tr>
                <tr>
                    <td colspan="2" height="30px"></td>
                </tr>
                <tr>
                   <td width="110px">Name City:</td>
                   <td width="100px" style="color:red;">
                        <select name="namecity"  id="list">
                            <c:forEach items="${lc1}" var="lction">
                                <option value="${lction.locationID}" >${lction.namecity}</option>
                            </c:forEach>
                        </select>
                    </td>
              </tr>
                <tr>
                    <td>Flight Name:</td>
                    <td style="color:red;"><input type="text" name="flightname" size="30" /></td>
                </tr>
                <tr>
                    <td>Price:</td>
                    <td style="color:red;"><input type="text" name="price" size="30" /></td>
                </tr>
                <tr>
                    <td>Departure Time:</td>
                    <td style="color:red;">
                        <input type="text" name="departurTime" size="10" />
                        <select name="timedeparture">
                            <option value="AM">AM</option>
                            <option value="PM">PM</option>
                        </select>
                     </td>
                </tr>
                <tr>
                    <td>Arrival Time:</td>
                    <td style="color:red;">
                        <input type="text" name="arrivalTime" size="10" />
                        <select name="timearrival">
                            <option value="AM">AM</option>
                            <option value="PM">PM</option>
                        </select>
                     </td>
                </tr>
                <tr>
                   <td width="110px">Departure City:</td>
                   <td width="100px" style="color:red;">
                        <select name="departureCity"  id="list">
                            <c:forEach items="${lc1}" var="lction">
                                <option value="${lction.namecity}" >${lction.namecity}</option>
                            </c:forEach>
                        </select>
                    </td>
              </tr>
               <tr>
                   <td>Arrival City:</td>
                   <td style="color:red;">
                        <select name="arrivalCity"  id="list">
                            <c:forEach items="${lc1}" var="lction">
                                <option value="${lction.namecity}">${lction.namecity}</option>
                            </c:forEach>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" height="20px"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" name="create" value="Add New Flight"  />
                        <input id="reset" type="reset" value="Reset" />
                    </td>
                </tr>
            </table>
        </form>
            <%
              }
              else
              {
                    flightID=session.getAttribute("flightID").toString();
                    flightName=session.getAttribute("flightName").toString();
                    departureTime=session.getAttribute("departureTime").toString();
                    arrivalTime=session.getAttribute("arrivalTime").toString();
                    timedeparture=session.getAttribute("timedeparture").toString();
                    timearra=session.getAttribute("timearrival").toString();
                    nameCity=session.getAttribute("nameCity").toString();
                    departurecity=session.getAttribute("departureCity").toString();
                    arrivalcity=session.getAttribute("arrivalCity").toString();
                    price=session.getAttribute("price").toString();
                    
                     LocationBean lcbean=new LocationBean();
                     Collection lction=lcbean.SelectLocationEdit(nameCity);
                     request.setAttribute("namecity",lction);
                     
                     Collection depcity=lcbean.SelectLocationEdit(departurecity);
                     request.setAttribute("decity",depcity);
                     
                     Collection Arrcity=lcbean.SelectLocationEdit(arrivalcity);
                     request.setAttribute("Arcity",Arrcity);
            %>
                 <form action="../ControllerFlight" method="post" name="formflightupdate" id="formflightupdate">
            <table width="650px" border="0" cellpadding="5" cellspacing="5">
                <tr>
                    <td colspan="2" class="font" align="center">Edit Flight</td>
                </tr>
                <tr>
                    <td colspan="2" height="30px"></td>
                </tr>
                <tr>
                    <td>Flight Id:</td>
                    <td style="color:red;"><input type="hidden" name="flightID" value="<%=flightID%>"/><b><%=flightID%></b></td>
                </tr>
                <tr>
                   <td width="110px">Name City:</td>
                   <td width="100px" style="color:red;">
                        <select name="namecity"  id="list">
                            <c:forEach items="${namecity}" var="lction">
                                <option value="${lction.locationID}" ${lction.editDrop}>${lction.namecity}</option>
                            </c:forEach>
                        </select>
                    </td>
              </tr>
                <tr>
                    <td>Flight Name:</td>
                    <td style="color:red;"><input type="text" name="flightname" size="30" value="<%=flightName%>" /></td>
                </tr>
                <tr>
                    <td>Price:</td>
                    <td><input type="text" name="price" size="30" value="<%=price%>" /></td>
                </tr>
                <tr>
                    <td>Departure Time:</td>
                    <td style="color:red;">
                       <input type="text" name="departurTime" value="<%=departureTime%>" size="10" />
                        <select name="timedeparture">
                             <%
                            if(timedeparture.equals("AM"))
                                {
                                %>
                                <option value="AM">AM</option> 
                                <option value="PM">PM</option>
                                <%
                                }
                              else
                                  {
                                  %>
                                  <option value="PM">PM</option>
                                  <option value="AM">AM</option>
                                  <%
                                  }
                            %>
                        </select>
                     </td>
                </tr>
                <tr>
                    <td>Arrival Time:</td>
                    <td style="color:red;">
                        <input type="text" name="arrivalTime" value="<%=arrivalTime%>" size="10" />
                         <select name="timearrival">
                            <%
                            if(timearra.equals("AM"))
                                {
                                %>
                                <option value="AM">AM</option> 
                                <option value="PM">PM</option>
                                <%
                                }
                              else
                                  {
                                  %>
                                  <option value="PM">PM</option>
                                  <option value="AM">AM</option>
                                  <%
                                  }
                            %>
                        </select>
                     </td>
                </tr>
                <tr>
                   <td width="110px">Departure City:</td>
                   <td width="100px" style="color:red;">
                        <select name="departureCity"  id="list">
                            <c:forEach items="${decity}" var="dct">
                                <option value="${dct.namecity}" ${dct.editDrop}>${dct.namecity}</option>
                            </c:forEach>
                        </select>
                    </td>
              </tr>
               <tr>
                   <td>Arrival City:</td>
                   <td style="color:red;">
                        <select name="arrivalCity"  id="list">
                            <c:forEach items="${Arcity}" var="city">
                                <option value="${city.namecity}" ${city.editDrop}>${city.namecity}</option>
                            </c:forEach>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" height="20px"></td>
                </tr>
                <tr>
                    <td align="right"><input type="submit" name="update" value="Update Flight"  /></td>
                   
                 </form>
                         <form action="../ControllerFlight" method="post">
                          <td>
                            <input id="reset" type="submit" name="reset" value="Cancel Update" />
                          </td>
                        </form>  
                </tr>
            </table>
        
            <%
                }
            %>
            </div>
            <br>
        <%
        FlightsBean cb=new FlightsBean();
        Collection cl1=cb.ListFights();
        request.setAttribute("lc",cl1);
        %>
        <div class="font">List Flight</div>    
        <table width="100%" id="Table">  
            <tr>
                <th>ID</th>
                <th>Name City</th>
                <th>Flight Name</th>
                <th>Departure Time</th>
                <th>Arrival Time</th>
                <th>Departure City</th>
                <th>Arrival City</th>
                <th>Price</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
            <pg:paging pageSize="10" url="management.jsp?page=ListHotel">
                <c:forEach items="${lc}" var="cr">
                    <pg:item>
                        <tr>
                            <td class="td">${cr.flightID}</td>
                             <td class="td">${cr.nameCity}</td>
                            <td class="td">${cr.flightName}</td>
                            <td class="td">${cr.departure_Time}</td>
                            <td class="td">${cr.arrival_Time}</td>
                            <td class="td">${cr.departure_City}</td>
                            <td class="td">${cr.arrival_City}</td>
                            <td class="td"><f:formatNumber value="${cr.price}" pattern="$#,###"/></td>
                            <td class="td">
                                <form action="../ControllerFlight" method="post">
                                    <input type="hidden" name="flightID" value="${cr.flightID}" /> 
                                    <input type="hidden" name="nameCity" value="${cr.nameCity}" />
                                    <input type="hidden" name="flightName" value="${cr.flightName}" />
                                    <input type="hidden" name="departureTime" value="${cr.departure_Time}" />
                                    <input type="hidden" name="arrivalTime" value="${cr.arrival_Time}" />
                                    <input type="hidden" name="departureCity" value="${cr.departure_City}" />
                                    <input type="hidden" name="arrivalCity" value="${cr.arrival_City}" />
                                    <input type="hidden" name="price" value="${cr.price}" />
                                    <input type="submit" class="sizeedit" name="edit" value="Edit"/>
                                </form>
                            </td>
                            <td class="td">
                                <form action="../ControllerFlight" method="post">
                                    <input type="hidden" name="flightID" value="${cr.flightID}" />
                                    <input type="submit" name="delete" value="Delete" OnClick="return confirm('Are you sure you want delete record this?');"/>
                                </form>
                            </td>
                        </tr>
                    </pg:item>       
                </c:forEach>
                <pg:index>
                    <pg:page><%=thisPage%></pg:page>
                </pg:index>
            </pg:paging>
        </table>
    
    </body>
</html>

